/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elementsDefense.towers.projectils;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import com.jme3.scene.shape.Sphere;
import com.jme3.scene.shape.Torus;
import elementsDefense.enemies.BasicEnemy;
import elementsDefense.enemies.HealthControl;
import elementsDefense.towers.Tower;

/**
 *
 * @author Ricardo
 */
public class Canonball extends Projectil{
        
    Geometry ball;
    Material matBlue;

    public Canonball(AssetManager assetManager, Node node, Tower source) {
        this.source = source;
        this.assetManager = assetManager;
        this.node =node;
        this.damage = 25;
        ball = new Geometry("ball", new Sphere(5, 5, 0.05f));
        matBlue = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matBlue.setColor("Color", ColorRGBA.Red);
        ball.setMaterial(matBlue);
    }
    
    public void shootAt(BasicEnemy target){
        this.target = target;
        node.attachChild(ball);
        homing = new HomingControl(source,target,this, 0.1f);
        ball.addControl(homing);
    }
    
    public void hit(){
        ball.removeFromParent();
        ball.removeControl(homing);
        homing.setEnabled(false);
        target.hit(this);
    }
}
